import {createStore} from "vuex";

export default createStore({
    state: {
        isCollapse: true,
        currentMenu: null,
        tabsList: [
            {
                path: '/',
                name: 'MainHome',
                label: '首页',
                icon: 'home'
            }
        ],
    },
    mutations: {
        //点击按钮实现折叠功能
        updateIsCollapse(state) {
            state.isCollapse = !state.isCollapse
        },
        //面包屑功能 + tab切换页面功能
        selectMenu(state, val) {
            if (val.name == 'home') {
                state.currentMenu == null
            } else {
                state.currentMenu = val
                let result = state.tabsList.findIndex(item => item.name === val.name)
                result == -1 ? state.tabsList.push(val) : ''
            }
        },
        //tab删除功能
        closeTab(state, val) {
            let res = state.tabsList.findIndex(item => item.name === val.name)
            state.tabsList.splice(res, 1)
        }
    }
})